import { createStore } from 'redux'

function reducer(state, action) {
  // console.log(state, action)
  // state = state || {
  //   // 给state 的初始值  state 就是我们所谓的数据源
  //   count: 100,
  //   name: "珠峰",
  //   age: 12
  // }
  if (!state) return {
    count: 100,
    name: "珠峰",
    age: 12
  }
  switch (action.type) {
    case 'add':
      return {
        // 返回的对象是一个新的state
        ...state,
        count: state.count + action.n
      }
    case 'minus':
      return {
        ...state,
        count: state.count - action.m
      }
    case 'addAge':
      return {
        ...state,
        age: state.age + action.num
      }
    default:
      return {
        ...state
      }
  }

}

let store = createStore(reducer)

export default store